package com.bemyapp;


import java.util.Random;

import com.bemyapp.model.Extract;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

public class DBAdapter {

	DatabaseHelper DBHelper;
	Context	context;
	SQLiteDatabase db;

	public class DatabaseHelper extends SQLiteOpenHelper{

		Context context;

		public DatabaseHelper(Context context) {
			super(context, "RepeatAfterMovies", null, 1);
			this.context = context;
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			db.execSQL("CREATE TABLE extract (" 
					+ "_id integer primary key autoincrement , "
					+ "pathToSample String text NOT NULL, "
					+ "french text NOT NULL,"
					+ "frenchTTS text NOT NULL,"
					+ "english text NOT NULL,"
					+ "englishTTS text NOT NULL,"
					+ "movieName text NOT NULL,"
					+ "actorName text NOT NULL,"
					+ "repeatDone smallint NOT NULL DEFAULT 0,"
					+ "translationDone smallint NOT NULL DEFAULT 0)" );	
			
			
			ContentValues val = new ContentValues();
			val.put("pathToSample", "ysnp.mp3");
			val.put("french", "Vous ne passerez pas");
			val.put("frenchTTS", "Vous ne passerez pas");
			val.put("english", "You shall not pass!");
			val.put("englishTTS", "voice/23.mp3");
			val.put("movieName", "Lord of the ring");
			val.put("actorName", "Gandalf");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "gogetem.wav");
			val.put("french", "Okay les filles... allons les chercher!");
			val.put("frenchTTS", "Okay les filles allons les chercher!");
			val.put("english", "Okay girls....let's go get'em!");
			val.put("englishTTS", "voice/01.mp3");
			val.put("movieName", "Grease");
			val.put("actorName", "Rizzo");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "improved.wav");
			val.put("french", "Notre situation ne s'est pas améliorée.");
			val.put("frenchTTS", "Notre situation ne s'est pas améliorée.");
			val.put("english", "Our situation has not improved.");
			val.put("englishTTS", "voice/02.mp3");
			val.put("movieName", "Indiana Jones and the Last Crusade");
			val.put("actorName", "Henry Jones");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "lookgood.wav");
			val.put("french", "Mec, je l'ai rendu trop swag!");
			val.put("frenchTTS", "Mec, je l'ai rendu trop swag!");
			val.put("english", "I make this look goood!");
			val.put("englishTTS", "voice/03.mp3");
			val.put("movieName", "Men In Black");
			val.put("actorName", "Agent J");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "nothank.wav");
			val.put("french", "Non, merci, je vais bien.");
			val.put("frenchTTS", "Non, merci, je vais bien.");
			val.put("english", "No, thank you, I'm fine.");
			val.put("englishTTS", "voice/04.mp3");
			val.put("movieName", "Men In Black");
			val.put("movieName", "Men In Black");
			val.put("actorName", "Agent J");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "fkwin98.wav");
			val.put("french", "Putain de Windows 98!");
			val.put("frenchTTS", "Putain de Windows 98!");
			val.put("english", "Fucking Windows 98!");
			val.put("englishTTS", "voice/05.mp3");
			val.put("movieName", "South Park the movie");
			val.put("actorName", "Army General");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "always2.wav");
			val.put("french", "Toujours deux ... Il y a un maître et un apprenti.");
			val.put("frenchTTS", "Toujours deux, Il y a un maître et un apprenti.");
			val.put("english", "Always two...There are a master and an apprentice.");
			val.put("englishTTS", "voice/06.mp3");
			val.put("movieName", "Star Wars : The Phantom Menace");
			val.put("actorName", "Yoda");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "battlewin.wav");
			val.put("french", "C'est un combat que je ne pense pas que nous pouvons gagner!");
			val.put("frenchTTS", "C'est un combat que je ne pense pas que nous pouvons gagner!");
			val.put("english", "This is a battle I do not think we can win!");
			val.put("englishTTS", "voice/07.mp3");
			val.put("movieName", "Star Wars : The Phantom Menace");
			val.put("actorName", "Panaka");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "contact.wav");
			val.put("french", "Tu dois me contacter!");
			val.put("frenchTTS", "Tu dois me contacter!");
			val.put("english", "You must contact me!");
			val.put("englishTTS", "voice/08.mp3");
			val.put("movieName", "Star Wars : The Phantom Menace");
			val.put("actorName", "Sio Bibble");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "gonnadie.wav");
			val.put("french", "Vous dites que les gens vont mourir?");
			val.put("frenchTTS", "Vous dites que les gens vont mourir?");
			val.put("english", "You say people gonna die?");
			val.put("englishTTS", "voice/09.mp3");
			val.put("movieName", "Star Wars : The Phantom Menace");
			val.put("actorName", "Jar Jar Binks");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "muchfear.wav");
			val.put("french", "Je sens beaucoup de peur en vous!");
			val.put("frenchTTS", "Je sens beaucoup de peur en vous!");
			val.put("english", "I sense much fear in you!");
			val.put("englishTTS", "voice/10.mp3");
			val.put("movieName", "Star Wars : The Phantom Menace");
			val.put("actorName", "Yoda");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "treaty.wav");
			val.put("french", "Je ne signerai aucun traité, sénateur!");
			val.put("frenchTTS", "Je ne signerai aucun traité, sénateur!");
			val.put("english", "I will sign no treaty, Senator!");
			val.put("englishTTS", "voice/11.mp3");
			val.put("movieName", "Star Wars : The Phantom Menace");
			val.put("actorName", "Queen Amidala");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "azizlite.wav");
			val.put("french", "Aziz lumière!");
			val.put("frenchTTS", "Aziz lumière!");
			val.put("english", "Aziz light!");
			val.put("englishTTS", "voice/12.mp3");
			val.put("movieName", "The Fifth Element");
			val.put("actorName", "Professor Pacoli");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "amazing.wav");
			val.put("french", "C'est... vraiment impressionnant.");
			val.put("frenchTTS", "C'est vraiment impressionnant.");
			val.put("english", "This....is really amazing.");
			val.put("englishTTS", "voice/13.mp3");
			val.put("movieName", "The Fifth Element");
			val.put("actorName", "Professor Pacoli");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "bluepill.wav");
			val.put("french", "Pourquoi oh pourquoi n'ai-je pas pris la pilule bleue?");
			val.put("frenchTTS", "Pourquoi oh pourquoi n'ai-je pas pris la pilule bleue?");
			val.put("english", "Why oh why didn't I take the blue pill?");
			val.put("englishTTS", "voice/14.mp3");
			val.put("movieName", "The Matrix");
			val.put("actorName", "Cypher");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "dinner.wav");
			val.put("french", "Je ne me souviens pas vous ne m'avez jamais apporté mon dîner.");
			val.put("frenchTTS", "Je ne me souviens pas vous ne m'avez jamais apporté mon dîner.");
			val.put("english", "I don't remember you ever bringing me dinner.");
			val.put("englishTTS", "voice/15.mp3");
			val.put("movieName", "The Matrix");
			val.put("actorName", "Cypher");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "iknewit.wav");
			val.put("french", "Je le savais! Il est le seul!");
			val.put("frenchTTS", "Je le savais! Il est le seul!");
			val.put("english", "I knew it!  He's the one!");
			val.put("englishTTS", "voice/16.mp3");
			val.put("movieName", "The Matrix");
			val.put("actorName", "Tank");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "realworld.wav");
			val.put("french", "Bienvenue dans le monde réel!");
			val.put("frenchTTS", "Bienvenue dans le monde réel!");
			val.put("english", "Welcome to the real world!");
			val.put("englishTTS", "voice/17.mp3");
			val.put("movieName", "The Matrix");
			val.put("actorName", "Morpheus");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "confront.wav");
			val.put("french", "Je n'aime pas les confrontations!");
			val.put("frenchTTS", "Je n'aime pas les confrontations!");
			val.put("english", "I don't like confrontations!");
			val.put("englishTTS", "voice/18.mp3");
			val.put("movieName", "Toy Story");
			val.put("actorName", "Rex");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "reach.wav");
			val.put("french", "Portée pour le ciel!");
			val.put("frenchTTS", "Portée pour le ciel!");
			val.put("english", "Reach for the sky!");
			val.put("englishTTS", "voice/19.mp3");
			val.put("movieName", "Toy Story");
			val.put("actorName", "Woody");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "iambuzz.wav");
			val.put("french", "Je suis Buzz l'éclair! Je viens en paix!");
			val.put("frenchTTS", "Je suis Beuz l'éclair! Je viens en paix!");
			val.put("english", "I am Buzz Lightyear! I come in peace!");
			val.put("englishTTS", "voice/20.mp3");
			val.put("movieName", "Toy Story");
			val.put("actorName", "Buzz");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "idiot.wav");
			val.put("french", "Quel idiot!");
			val.put("frenchTTS", "Quel idiot!");
			val.put("english", "What an idiot!");
			val.put("englishTTS", "voice/21.mp3");
			val.put("movieName", "Toy Story");
			val.put("actorName", "Woody");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			val = new ContentValues();
			val.put("pathToSample", "dntthink.wav");
			val.put("french", "Ne pense même pas à ce sujet, cow-boy!");
			val.put("frenchTTS", "Ne pense même pas à ce sujet, cow-boy!");
			val.put("english", "Don't even think about it, cowboy!");
			val.put("englishTTS", "voice/22.mp3");
			val.put("movieName", "Toy Story");
			val.put("actorName", "Buzz");
			val.put("repeatDone", 0);
			val.put("translationDone", 0);
			db.insert("extract", null, val);
			
			
			
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			Toast.makeText(context, "Mise à jour de la DB ! (de "+oldVersion+" vers "+newVersion+")", 1000);
			db.execSQL("DROP TABLE IF EXISTS extract");
			onCreate(db);
		}

	}

	public DBAdapter(Context c){
		this.context = c;
		DBHelper = new DatabaseHelper(this.context);
	}

	public DBAdapter open(){
		db = DBHelper.getWritableDatabase();
		return this;
	}

	public void close(){
		db.close();
	}
	/**
	 * Return an Extract to repeat
	 * @param newRepeat True : Never used, false : already used or not
	 * @return
	 */
	public Extract getExtractToRepeat(boolean newRepeat){
		Cursor c;
		Extract e;
		if(newRepeat)
			c = db.query("extract", new String[]{ "_id", "pathToSample","french","frenchTTS","english","englishTTS","movieName","actorName","repeatDone","translationDone"}, "repeatDone=0", null, null, null,null);
		else
			c = db.query("extract", new String[]{ "_id", "pathToSample","french","frenchTTS","english","englishTTS","movieName","actorName","repeatDone","translationDone"}, null, null, null, null,null);
		Random r = new Random();
		c.moveToPosition(r.nextInt(c.getCount()));
		e = new Extract(c.getInt(0), c.getString(1), c.getString(2), c.getString(3),c.getString(4),c.getString(5), c.getString(6), c.getString(7), (c.getInt(8)==1)?true:false, (c.getInt(9)==1)?true:false);
		
		return e;
	}
	
	/**
	 * Return an Extrat to translate
	 * @param newTranslation True : never used, false: already used or not
	 * @return
	 */
	public Extract getExtractToTranslate(boolean newTranslation){
		Cursor c;
		Extract e;
		if(newTranslation)
			c = db.query("extract", new String[]{ "_id", "pathToSample","french","frenchTTS","english","englishTTS","movieName","actorName","repeatDone","translationDone"}, "translationDone=0", null, null, null,null);
		else
			c = db.query("extract", new String[]{ "_id", "pathToSample","french","frenchTTS","english","englishTTS","movieName","actorName","repeatDone","translationDone"}, null, null, null, null,null);
		Random r = new Random();
		c.moveToPosition(r.nextInt(c.getCount()));
		e = new Extract(c.getInt(0), c.getString(1), c.getString(2), c.getString(3),c.getString(4),c.getString(5), c.getString(6), c.getString(7), (c.getInt(8)==1)?true:false, (c.getInt(9)==1)?true:false);
		
		return e;	
	}
	
	/**
	 * Return and Extract to use when the user did 3 good repetition ! 
	 * @return
	 */
	public Extract getExtractToTranslateAlreadyRepeated(){
		Cursor c;
		Extract e;
		c = db.query("extract", new String[]{ "_id", "pathToSample","french","frenchTTS","english","englishTTS","movieName","actorName","repeatDone","translationDone"}, "translationDone=0 and repeatDone=1", null, null, null,null);
		Random r = new Random();
		c.moveToPosition(r.nextInt(c.getCount()));
		e = new Extract(c.getInt(0), c.getString(1), c.getString(2), c.getString(3),c.getString(4),c.getString(5), c.getString(6), c.getString(7), (c.getInt(8)==1)?true:false, (c.getInt(9)==1)?true:false);
		
		return e;	
	}
	
	

	public long createExtract(String textExtract){
		ContentValues val = new ContentValues();
		val.put("textExtract", textExtract);
		return db.insert("extract", null, val);
	}  
	
	public boolean extractIsAlreadyRepeated(int id){
		Cursor c = db.rawQuery("SELECT COUNT(*) FROM extract WHERE extract._id=" + id, null);
		c.moveToFirst();	
		if(c.getInt(0)==1){	// we've got the good one
			ContentValues val = new ContentValues();
			val.put("repeatDone", 1);
			return(db.update("extract", val, "_id="+id, null)>0);
		}
		return false;
	} 

	public boolean extractIsAlreadyTranslated(int id){
		Cursor c = db.rawQuery("SELECT COUNT(*) FROM extract WHERE extract._id=" + id, null);
		c.moveToFirst();	
		if(c.getInt(0)==1){	// we've got the good one
			ContentValues val = new ContentValues();
			val.put("translationDone", 1);
			return(db.update("extract", val, "_id="+id, null)>0);
		}
		return false;
	} 


	//	/* Gestion des Catégories */	
	//	public long creerCategorie(String nom){
	//		ContentValues val = new ContentValues();
	//		val.put("nomCategorie", nom);
	//		return db.insert("Categorie", null, val);
	//	}   
	//	public boolean supprimerCategorie(long l){
	//		Cursor c = db.rawQuery("SELECT COUNT(*) FROM Item WHERE Item.categorie=" + l, null);
	//		c.moveToFirst();		
	//		if(c.getInt(0)==0)	return db.delete("Categorie", "_id="+l, null)>0;
	//		else return false;
	//	}
	//	public Cursor recupererCategorie(){
	//		return db.query("Categorie", new String[]{ "_id", "nomCategorie"}, null, null, null, null, "nomCategorie");
	//	}
	//	
	//	public boolean mettreAJourCategorie(int l,String newName){
	//		Cursor c = db.rawQuery("SELECT COUNT(*) FROM Item WHERE Item.categorie=" + l, null);
	//		c.moveToFirst();	
	//		if(c.getInt(0)==0){	// si il n'y a pas d'item concerné, on del
	//			ContentValues val = new ContentValues();
	//			val.put("nomCategorie", newName);
	//			return(db.update("Categorie", val, "_id="+l, null)>0);
	//		}
	//		else return false;
	//	}
	//	
	//	
	//	/* Gestion des TypeMedia */	
	//	public long creerTypeMedia(String nom){
	//		ContentValues val = new ContentValues();
	//		val.put("nomTypeMedia", nom);
	//		return db.insert("TypeMedia", null, val);
	//	}
	//	
	//	public boolean supprimerTypeMedia(int l){
	//		Cursor c = db.rawQuery("SELECT COUNT(*) FROM Item WHERE Item.typeMedia=" + l, null);
	//		c.moveToFirst();	
	//		if(c.getInt(0)==0){	// si il n'y a pas d'item concerné, on del
	//			return(db.delete("TypeMedia", "_id="+l, null)>0);
	//		}
	//		else return false;
	//	}
	//	
	//	public boolean mettreAJourTypeMedia(int l,String newName){
	//		Cursor c = db.rawQuery("SELECT COUNT(*) FROM Item WHERE Item.typeMedia=" + l, null);
	//		c.moveToFirst();	
	//		if(c.getInt(0)==0){	// si il n'y a pas d'item concerné, on del
	//			ContentValues val = new ContentValues();
	//			val.put("nomTypeMedia", newName);
	//			return(db.update("TypeMedia", val, "_id="+l, null)>0);
	//		}
	//		else return false;
	//	}
	//	
	//	
	//	public Cursor recupererTypeMedia(){
	//		return db.query("TypeMedia", new String[]{ "_id", "nomTypeMedia"}, null, null, null, null, "nomTypeMedia");
	//	}
	//	
	//	/* Gestion des Items */
	//	public long creerItem(String codeBarre, String titre, String description, String image, String preteA,String pretePar, String auteur, int typeMedia, int categorie){
	//		ContentValues val = new ContentValues();
	//		val.put("codeBarre", codeBarre);
	//		val.put("titre", titre);
	//		val.put("description", description);
	//		val.put("image", image);
	//		val.put("preteA", preteA);
	//		val.put("pretePar", pretePar);
	//		val.put("auteur", auteur);
	//		val.put("typeMedia", typeMedia);
	//		val.put("categorie", categorie);
	//		return db.insert("Item", null, val);
	//	}
	//	
	//	public boolean supprimerItem(long l){
	//		return db.delete("Item", "_id="+l, null)>0;
	//	}
	//	
	//	public Cursor recupererItemComplet(){
	//		//return db.query("Item", new String[]{ "_id", "codeBarre", "titre", "description","image","preteA","pretePar","auteur","typeMedia","categorie"}, null, null, null, null, null);
	//		return db.rawQuery("SELECT * FROM Item", null);
	//	}
	//	
	//	public Cursor recupererItemCompletParCategorie(int categorie){
	//		return db.query("Item", new String[]{ "_id", "codeBarre", "titre", "description","image","preteA","pretePar","auteur","typeMedia","categorie"}, "categorie="+categorie, null, null, null, null);
	//	}
	//
	//	public Cursor recupererItemCompletParTypeMedia(int typeMedia){
	//		return db.query("Item", new String[]{ "_id", "codeBarre", "titre", "description","image","preteA","pretePar","auteur","typeMedia","categorie"}, "typeMedia="+typeMedia, null, null, null, null);
	//	}
	//	
	//
	//	public Cursor recupererItemCompletParId(int id){
	//		return db.query("Item", new String[]{ "_id", "codeBarre", "titre", "description","image","preteA","pretePar","auteur","typeMedia","categorie"}, "_id="+id, null, null, null, null);
	//	}
	//	
	//	public int recupererDernierItemAjoute(){
	//		Cursor c = db.rawQuery("SELECT last_insert_rowid()", null);
	//		c.moveToFirst();
	//		return c.getInt(0);
	//		
	//	}
	//	
	//	/**
	//	 * 
	//	 * @param preteur Si null, alors on affiche tout les items prêtés par tout le monde, sinon, que par ce preteur (on fait un like)
	//	 * @return
	//	 */
	//	public Cursor recupererItemCompletPretePar(String preteur){
	//		if(preteur==null)
	//			//return db.query("Item", new String[]{ "_id", "codeBarre", "titre", "description","image","preteA","pretePar","auteur","typeMedia","categorie"}, "pretePar NOT NULL", null, null, null, null);
	//		return db.rawQuery("SELECT Item._id, codeBarre, titre, description, image, preteA, pretePar, " +
	//				"auteur, TypeMedia._id as idTypeMedia, TypeMedia.nomTypeMedia, Categorie._id as idCategorie, Categorie.nomCategorie " +
	//				"FROM Item " +
	//				"INNER JOIN Categorie ON Categorie._id=Item.categorie " +
	//				"INNER JOIN TypeMedia ON TypeMedia._id=Item.typeMedia WHERE pretePar NOT NULL" , null);
	//		else
	//			return db.rawQuery("SELECT Item._id, codeBarre, titre, description, image, preteA, pretePar, " +
	//					"auteur, TypeMedia._id as idTypeMedia, TypeMedia.nomTypeMedia, Categorie._id as idCategorie, Categorie.nomCategorie " +
	//					"FROM Item " +
	//					"INNER JOIN Categorie ON Categorie._id=Item.categorie " +
	//					"INNER JOIN TypeMedia ON TypeMedia._id=Item.typeMedia WHERE pretePar LIKE %"+preteur+"%" , null);	}
	//	
	//	/**
	//	 * 
	//	 * @param preteur Si null, alors on affiche tout les items prêtés à tout le monde, sinon, que à cet ami (on fait un like)
	//	 * @return
	//	 */
	//	public Cursor recupererItemCompletPreteA(String preteur){
	//		if(preteur==null)
	//			return db.rawQuery("SELECT Item._id, codeBarre, titre, description, image, preteA, pretePar, " +
	//					"auteur, TypeMedia._id as idTypeMedia, TypeMedia.nomTypeMedia, Categorie._id as idCategorie, Categorie.nomCategorie " +
	//					"FROM Item " +
	//					"INNER JOIN Categorie ON Categorie._id=Item.categorie " +
	//					"INNER JOIN TypeMedia ON TypeMedia._id=Item.typeMedia WHERE preteA NOT NULL" , null);		
	//		else
	//			return db.rawQuery("SELECT Item._id, codeBarre, titre, description, image, preteA, pretePar, " +
	//					"auteur, TypeMedia._id as idTypeMedia, TypeMedia.nomTypeMedia, Categorie._id as idCategorie, Categorie.nomCategorie " +
	//					"FROM Item " +
	//					"INNER JOIN Categorie ON Categorie._id=Item.categorie " +
	//					"INNER JOIN TypeMedia ON TypeMedia._id=Item.typeMedia WHERE preteA LIKE %"+preteur+"%" , null);
	//	}
	//	/**
	//	 * DEBUGGG
	//	 * @return
	//	 */
	//	public long addTestTom(){
	//		ContentValues val = new ContentValues();
	//		val.put("codeBarre", "909090");
	//		val.put("titre", "TEST TOM 1");
	//		val.put("description", "DESC TOM 1");
	//		val.put("image", "");
	//		val.put("preteA", "preteur 1");
	//		val.put("pretePar", "preteur 1");
	//		val.put("auteur", "aut1");
	//		val.put("typeMedia", "");
	//		val.put("categorie", "");
	//		return db.insert("Item", null, val);
	//	}
	//	/**
	//	 * 
	//	 * @param id
	//	 * @param preteur
	//	 * @param sens true=preteA, false=pretePAR
	//	 * @return
	//	 */
	//	public boolean preteCetItem(int id, String preteur, boolean sens){
	//		Cursor c = db.rawQuery("SELECT COUNT(*) FROM Item WHERE Item._id=" + id, null);
	//		c.moveToFirst();	
	//		if(c.getInt(0)>0){	// Si on a trouvé l'item, on le met à jour
	//			ContentValues val = new ContentValues();
	//			if(sens)	val.put("preteA", preteur);
	//			else		val.put("pretePar", preteur);
	//			int aaa = db.update("Item", val, "_id="+id, null);
	//			return(aaa>0);
	//		}
	//		return false;
	//	}
	//	/**
	//	 * 
	//	 * @param _codeBarre
	//	 * @return True si l'item existe déjà, false sinon
	//	 */
	//	public boolean verifExistenceItem(String _codeBarre){
	//		Cursor c = db.rawQuery("SELECT COUNT(*) FROM Item WHERE codeBarre =\'"+_codeBarre+"'", null);
	//		c.moveToFirst();
	//		return(c.getInt(0)>0);
	//	}


}